package lx;

public class Girlfriend {
    private String name;
    private int age;

    public Girlfriend() {
    }

    public Girlfriend(String name, int age) {
        this.name = name;
        this.age = age;
    }

    /**
     * 获取
     *
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     *
     * @param name
     */
    public void setName(String name) {
        //  姓名的长度在 3 - 10之间，

        if (name.length() < 3 || name.length() > 10) {
            throw new NameFormatExcepion(name+"不符合范围");//运行出错误 运行时错误可以不用写throws
        }
        this.name = name;
    }

    /**
     * 获取
     *
     * @return age
     */
    public int getAge() {
        return age;
    }

    /**
     * 设置
     *
     * @param age
     */
    public void setAge(int age) {
        // 年龄的范围为 18 - 40岁
        if (age < 18 || age > 40) {
          throw  new AgeFormatExcepion(age+"不符合范围");

        }
        this.age = age;
    }

    public String toString() {
        return "Girlfriend{name = " + name + ", age = " + age + "}";
    }
}
